from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-08-09 14:12:27.498477
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Mon, 09, Aug, 2021
Time: 14:12:31
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -45.5960
Nobs: 378.000 HQIC: -46.1611
Log likelihood: 4057.49 FPE: 6.18098e-21
AIC: -46.5329 Det(Omega_mle): 4.88651e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.492897 0.096673 5.099 0.000
L1.Burgenland 0.106214 0.049820 2.132 0.033
L1.Kärnten -0.116549 0.024071 -4.842 0.000
L1.Niederösterreich 0.168545 0.106030 1.590 0.112
L1.Oberösterreich 0.079775 0.104534 0.763 0.445
L1.Salzburg 0.292489 0.051040 5.731 0.000
L1.Steiermark 0.014703 0.067763 0.217 0.828
L1.Tirol 0.136625 0.053548 2.551 0.011
L1.Vorarlberg -0.108320 0.048050 -2.254 0.024
L1.Wien -0.061397 0.093740 -0.655 0.512
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const -0.024641 0.233475 -0.106 0.916
L1.Burgenland -0.032039 0.120320 -0.266 0.790
L1.Kärnten 0.036185 0.058133 0.622 0.534
L1.Niederösterreich -0.211795 0.256074 -0.827 0.408
L1.Oberösterreich 0.545930 0.252460 2.162 0.031
L1.Salzburg 0.308550 0.123266 2.503 0.012
L1.Steiermark 0.111232 0.163655 0.680 0.497
L1.Tirol 0.299034 0.129323 2.312 0.021
L1.Vorarlberg -0.017134 0.116045 -0.148 0.883
L1.Wien -0.002782 0.226392 -0.012 0.990
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.265441 0.050057 5.303 0.000
L1.Burgenland 0.096902 0.025797 3.756 0.000
L1.Kärnten -0.005447 0.012464 -0.437 0.662
L1.Niederösterreich 0.228652 0.054902 4.165 0.000
L1.Oberösterreich 0.146500 0.054127 2.707 0.007
L1.Salzburg 0.037662 0.026428 1.425 0.154
L1.Steiermark 0.014990 0.035088 0.427 0.669
L1.Tirol 0.077066 0.027727 2.779 0.005
L1.Vorarlberg 0.057528 0.024880 2.312 0.021
L1.Wien 0.081109 0.048538 1.671 0.095
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.200924 0.049045 4.097 0.000
L1.Burgenland 0.043844 0.025275 1.735 0.083
L1.Kärnten -0.006481 0.012212 -0.531 0.596
L1.Niederösterreich 0.125601 0.053792 2.335 0.020
L1.Oberösterreich 0.302846 0.053033 5.711 0.000
L1.Salzburg 0.099778 0.025894 3.853 0.000
L1.Steiermark 0.141887 0.034378 4.127 0.000
L1.Tirol 0.077874 0.027166 2.867 0.004
L1.Vorarlberg 0.056102 0.024377 2.301 0.021
L1.Wien -0.043809 0.047557 -0.921 0.357
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.209903 0.098323 2.135 0.033
L1.Burgenland -0.055364 0.050670 -1.093 0.275
L1.Kärnten -0.037880 0.024482 -1.547 0.122
L1.Niederösterreich 0.064759 0.107840 0.601 0.548
L1.Oberösterreich 0.192954 0.106318 1.815 0.070
L1.Salzburg 0.266258 0.051911 5.129 0.000
L1.Steiermark 0.081982 0.068920 1.190 0.234
L1.Tirol 0.127282 0.054462 2.337 0.019
L1.Vorarlberg 0.120865 0.048870 2.473 0.013
L1.Wien 0.033219 0.095340 0.348 0.728
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.036405 0.077174 0.472 0.637
L1.Burgenland 0.026263 0.039771 0.660 0.509
L1.Kärnten 0.051158 0.019216 2.662 0.008
L1.Niederösterreich 0.196295 0.084644 2.319 0.020
L1.Oberösterreich 0.343110 0.083449 4.112 0.000
L1.Salzburg 0.048121 0.040745 1.181 0.238
L1.Steiermark -0.001990 0.054095 -0.037 0.971
L1.Tirol 0.114350 0.042747 2.675 0.007
L1.Vorarlberg 0.062611 0.038358 1.632 0.103
L1.Wien 0.124843 0.074833 1.668 0.095
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.166235 0.093906 1.770 0.077
L1.Burgenland 0.032472 0.048394 0.671 0.502
L1.Kärnten -0.059000 0.023382 -2.523 0.012
L1.Niederösterreich -0.106369 0.102996 -1.033 0.302
L1.Oberösterreich 0.187380 0.101542 1.845 0.065
L1.Salzburg 0.029622 0.049579 0.597 0.550
L1.Steiermark 0.300231 0.065824 4.561 0.000
L1.Tirol 0.489432 0.052016 9.409 0.000
L1.Vorarlberg 0.074322 0.046675 1.592 0.111
L1.Wien -0.111121 0.091058 -1.220 0.222
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.159243 0.102319 1.556 0.120
L1.Burgenland -0.004887 0.052729 -0.093 0.926
L1.Kärnten 0.063468 0.025477 2.491 0.013
L1.Niederösterreich 0.199402 0.112222 1.777 0.076
L1.Oberösterreich -0.130424 0.110639 -1.179 0.238
L1.Salzburg 0.246837 0.054020 4.569 0.000
L1.Steiermark 0.158409 0.071721 2.209 0.027
L1.Tirol 0.049334 0.056675 0.870 0.384
L1.Vorarlberg 0.122849 0.050856 2.416 0.016
L1.Wien 0.138930 0.099214 1.400 0.161
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.523884 0.055088 9.510 0.000
L1.Burgenland -0.021892 0.028389 -0.771 0.441
L1.Kärnten -0.009750 0.013717 -0.711 0.477
L1.Niederösterreich 0.189521 0.060420 3.137 0.002
L1.Oberösterreich 0.248853 0.059568 4.178 0.000
L1.Salzburg 0.021314 0.029084 0.733 0.464
L1.Steiermark -0.024156 0.038614 -0.626 0.532
L1.Tirol 0.075311 0.030514 2.468 0.014
L1.Vorarlberg 0.060195 0.027381 2.198 0.028
L1.Wien -0.061621 0.053417 -1.154 0.249
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.023547 0.065014 0.125624 0.111597 0.031375 0.062938 -0.004311 0.169128
Kärnten 0.023547 1.000000 -0.059698 0.128676 0.043961 0.069276 0.457949 -0.093925 0.100843
Niederösterreich 0.065014 -0.059698 1.000000 0.284793 0.092414 0.276657 0.016234 0.141335 0.255555
Oberösterreich 0.125624 0.128676 0.284793 1.000000 0.177139 0.295897 0.166225 0.121470 0.127878
Salzburg 0.111597 0.043961 0.092414 0.177139 1.000000 0.127236 0.046254 0.107962 0.052159
Steiermark 0.031375 0.069276 0.276657 0.295897 0.127236 1.000000 0.132957 0.087762 -0.025565
Tirol 0.062938 0.457949 0.016234 0.166225 0.046254 0.132957 1.000000 0.036907 0.126504
Vorarlberg -0.004311 -0.093925 0.141335 0.121470 0.107962 0.087762 0.036907 1.000000 -0.046257
Wien 0.169128 0.100843 0.255555 0.127878 0.052159 -0.025565 0.126504 -0.046257 1.000000